package com.wenhui.nzapp.ui.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.gzwh.weblib.bean.NzDinnerRegion;
import com.gzwh.weblib.bean.NzProductCategory;
import com.wenhuitec.productlib.R;

import java.util.List;

public class DinnerQrAreManagerAdapter extends RecyclerView.Adapter<DinnerQrAreManagerAdapter.ViewHolder> {


    private Context context;
    private List<NzDinnerRegion> list;

    private OnUserClick mOnUserClick;

    public interface OnUserClick {
        void onClick(NzDinnerRegion nzDinnerRegion);
    }

    public void setmOnUserClick(OnUserClick mOnUserClick) {
        this.mOnUserClick = mOnUserClick;
    }

    public DinnerQrAreManagerAdapter(Context context, List<NzDinnerRegion> list, OnUserClick mOnUserClick) {
        this.context = context;
        this.list = list;
        this.mOnUserClick = mOnUserClick;
    }

    @NonNull
    @Override
    public DinnerQrAreManagerAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_category, null);
        DinnerQrAreManagerAdapter.ViewHolder holder = new DinnerQrAreManagerAdapter.ViewHolder(view);
        return holder;
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        private TextView cateNameTv;
        private ImageView menu;
        private TextView foodNumTv;
        private TextView editBut;
        private LinearLayout cateMainLinear;

        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            cateNameTv = itemView.findViewById(R.id.cateNameTv);
            menu = itemView.findViewById(R.id.item_list_menu_imageView);
            foodNumTv = itemView.findViewById(R.id.foodNumTv);
            editBut = itemView.findViewById(R.id.editBut);
            cateMainLinear = itemView.findViewById(R.id.cate_main_linear);
        }
    }

    @Override
    public void onBindViewHolder(@NonNull DinnerQrAreManagerAdapter.ViewHolder viewHolder, int i) {
        String str = list.get(i).getName();
        viewHolder.cateNameTv.setText(str);
//        viewHolder.foodNumTv.setText(list.get(i).getCounts() + "个商品");
        viewHolder.menu.setVisibility(View.GONE);
        viewHolder.editBut.setVisibility(View.VISIBLE);
        viewHolder.foodNumTv.setVisibility(View.GONE);
        viewHolder.cateMainLinear.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mOnUserClick != null) {
                    mOnUserClick.onClick(list.get(i));
                }
            }
        });

    }

    @Override
    public int getItemCount() {
        return list.size();
    }
}
